import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  JoinColumn,
  Relation,
  JoinTable,
  ManyToMany,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { User } from 'src/users/entities/user.entity';
import { Tag } from './tag.entity';
@Entity()
export class Note {
  @ApiProperty({ description: '笔记ID' })
  @PrimaryGeneratedColumn()
  id: number;
  // 作者信息
  @ApiProperty({ description: '作者信息', type: () => User })
  @ManyToOne(() => User)
  @JoinColumn({ name: 'user_id' })
  author: Relation<User>;
  // 笔记标签
  @ApiProperty({ description: '笔记标签', type: () => [Tag] })
  @JoinTable()
  @ManyToMany(() => Tag, (tag) => tag.notes, { cascade: true })
  tags: Tag[];
  @ApiProperty({ description: '笔记标题' })
  @Column()
  title: string;
  @ApiProperty({ description: '笔记内容' })
  @Column()
  content: string;
  @ApiProperty({ description: '文件列表', type: [] })
  @Column({ type: 'json', nullable: true })
  fileIds: number[];
  // 笔记是否公开
  @ApiProperty({ description: '是否公开' })
  @Column({ default: true })
  is_public: boolean;
  // 笔记创建时间
  @ApiProperty({ description: '创建时间' })
  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  created_at: Date;
  @ApiProperty({ description: '更新时间' })
  @Column({
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP',
    onUpdate: 'CURRENT_TIMESTAMP',
  })
  updated_at: Date;
}
